package it.crosato.stage.server.model.phylogeny;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;

public class TreeFrame extends Frame {

	private static final long serialVersionUID = 3527298066031602318L;
	
	TreeCanvas tc;

	/**
	 * Costruisce il frame contenente l'albero filogenetico
	 * @param c il cluster radice dell'albero
	 */
	public TreeFrame(Cluster c) {
		tc = new TreeCanvas(c);
		add(tc, "Center");
		setBackground(new Color(230,230,250));
		setUndecorated(true);
		pack();
		setVisible(true);
	}

	public void setCluster(Cluster c){
		tc.setCluster(c);
	}
}

class TreeCanvas extends Canvas {

	private static final long serialVersionUID = 4093319832126552849L;
	
	Cluster c;

	public TreeCanvas(Cluster c){
		this.c = c;
	}
	public void setCluster(Cluster c){
		this.c = c; repaint();
	}
	public void paint(Graphics g) {
		Dimension d = getSize();
		if (c != null)
			c.draw(g, d.width, d.height);
	}
	public Dimension getPreferredSize(){
		return new Dimension(550, 300);
	}
	public Dimension getMinimumSize(){
		return getPreferredSize();
	}
}
